package com.xiangxiao.rpan.data.enums;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Projectname: rpan-data
 * @Author: xiangxiao
 * @Email: 573768011@qq.com
 * @Data:2024/5/31 1:54
 */
public enum MessageTypeEnum {
  /**
   * 消息类型
   */
  FILEUPLOAD(0, "文件上传", "file-upload"),
  FILEDOWNLOAD(1, "文件下载", "file-download"),
  FLODERUPLOAD(2, "文件夹上传", "floder-upload"),
  FLODDOWNLOAD(3, "文件夹下载", "floder-download"),
    ;

  private final String desc;
  private final Integer code;
  private final String mqttTopic;

  MessageTypeEnum(Integer code, String desc, String mqttTopic) {
    this.desc = desc;
    this.code = code;
    this.mqttTopic = mqttTopic;
  }

  public static MessageTypeEnum getMessageTypeEnum(Integer type) {
    if (type == null) {
      return null;
    }
    return Arrays.stream(values())
      .filter(monitorTypeEnum -> Objects.equals(monitorTypeEnum.code, type))
      .findFirst().orElse(null);
  }

  public static List<String> getAllMQqttTopics() {
    return Arrays.stream(MessageTypeEnum.values()).map(a -> a.getMqttTopic()).collect(Collectors.toList());
  }

  public static MessageTypeEnum getByCode(Integer code) {
    if (code == null) {
      return null;
    }
    return Arrays.stream(MessageTypeEnum.values())
      .filter(a -> Objects.equals(a.getCode(), code))
      .findFirst().orElse(null);
  }

  public String getDesc() {
    return desc;
  }

  public Integer getCode() {
    return code;
  }

  public String getMqttTopic() {
    return mqttTopic;
  }
}
